Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
matrix.h
Go to the documentation of this file.
1 // Copyright (c) 2014, 2015, 2016, NXP Semiconductors N.V.,
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of NXP Semiconductors N.V. nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL NXP SEMICONDUCTORS N.V. BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 /*! \file matrix.h
27  \brief Matrix manipulation functions
28 
29  Contains functions for basic manipulation of 3x3 matrices
30 */
31 
32 #ifndef MATRIX_H
33 #define MATRIX_H
34 
35 // function prototypes
36 
37 /// function sets the 3x3 matrix A to the identity matrix
38 void f3x3matrixAeqI(
39  float A[][3]
40 );
41 /// function sets 3x3 matrix A to 3x3 matrix B
42 void f3x3matrixAeqB(
43  float A[][3],
44  float B[][3]
45 );
46 /// function sets the matrix A to the identity matrix
47 void fmatrixAeqI(
48  float *A[], ///< pointer to the matrix
49  int16 rc ///< dimension of the matrix
50 );
51 /// function sets every entry in the 3x3 matrix A to a constant scalar
53  float A[][3],
54  float Scalar
55 );
56 /// function directly calculates the symmetric inverse of a symmetric 3x3 matrix
57 /// only the on and above diagonal terms in B are used and need to be specified
59  float A[][3],
60  float B[][3]
61 );
62 /// function multiplies all elements of 3x3 matrix A by the specified scalar
64  float A[][3],
65  float Scalar
66 );
67 /// function negates all elements of 3x3 matrix A
69  float A[][3]
70 );
71 /// function calculates the determinant of a 3x3 matrix
72 float f3x3matrixDetA(
73  float A[][3]
74 );
75 /// function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1]
76 /// stored in the top left of a 10x10 array A[10][10]
77 void fEigenCompute10(
78  float A[][10], ///< real symmetric matrix A[0..n-1][0..n-1]
79  float eigval[], ///< eigval[0..n-1] returns the eigenvalues of A[][].
80  float eigvec[][10], ///< eigvec[0..n-1][0..n-1] returns the normalized eigenvectors of A[][]
81  int8 n ///< n can vary up to and including 10 but the matrices A and eigvec must have 10 columns.
82 );
83 /// function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1]
84 /// stored in the top left of a 4x4 array A[4][4]
85 /// A[][] is changed on output.
86 /// The eigenvectors are not sorted by value.
87 /// This function is identical to eigencompute10 except for the workaround for 4x4 matrices since C cannot
88 /// handle functions accepting matrices with variable numbers of columns.
89 void fEigenCompute4(
90  float A[][4],
91  float eigval[], ///< eigval[0..n-1] returns the eigenvalues of A[][].
92  float eigvec[][4], ///< eigvec[0..n-1][0..n-1] returns the normalized eigenvectors of A[][]
93  int8 n ///< n can vary up to and including 4 but the matrices A and eigvec must have 4 columns.
94 );
95 void fComputeEigSlice(
96  float fmatA[10][10],
97  float fmatB[10][10],
98  float fvecA[10],
99  int8 i,
100  int8 j,
101  int8 iMatrixSize
102 );
103 /// function uses Gauss-Jordan elimination to compute the inverse of matrix A in situ
104 /// on exit, A is replaced with its inverse
105 void fmatrixAeqInvA(
106  float *A[],
107  int8 iColInd[],
108  int8 iRowInd[],
109  int8 iPivot[],
110  int8 isize,
111  int8* pierror
112 );
113 /// function rotates 3x1 vector u onto 3x1 vector using 3x3 rotation matrix fR.
114 /// the rotation is applied in the inverse direction if itranpose is true
115 void fveqRu(
116  float fv[], ///< 3x1 output vector
117  float fR[][3], ///< rotation matrix
118  float fu[], ///< 3x1 input vector
119  int8 itranspose ///< true if inverse direction desired
120 );
121 /// function multiplies the 3x1 vector V by a 3x3 matrix A
122 void fVeq3x3AxV(
123  float V[3], ///< used for both input and output
124  float A[][3]
125 );
126 
127 #endif // #ifndef MATRIX_H
void fEigenCompute4(float A[][4], float eigval[], float eigvec[][4], int8 n)
function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1] stored in the top left of a 4x4 array A[4][4] A[][] is changed on output. The eigenvectors are not sorted by value. This function is identical to eigencompute10 except for the workaround for 4x4 matrices since C cannot handle functions accepting matrices with variable numbers of columns.
Definition: matrix.c:407
float f3x3matrixDetA(float A[][3])
function calculates the determinant of a 3x3 matrix
Definition: matrix.c:209
void fVeq3x3AxV(float V[3], float A[][3])
function multiplies the 3x1 vector V by a 3x3 matrix A
Definition: matrix.c:871
#define B
Definition: status.c:50
void f3x3matrixAeqScalar(float A[][3], float Scalar)
function sets every entry in the 3x3 matrix A to a constant scalar
Definition: matrix.c:109
void f3x3matrixAeqI(float A[][3])
function sets the 3x3 matrix A to the identity matrix
Definition: matrix.c:45
void f3x3matrixAeqInvSymB(float A[][3], float B[][3])
function directly calculates the symmetric inverse of a symmetric 3x3 matrix only the on and above di...
Definition: matrix.c:168
void f3x3matrixAeqB(float A[][3], float B[][3])
function sets 3x3 matrix A to 3x3 matrix B
Definition: matrix.c:66
void f3x3matrixAeqMinusA(float A[][3])
function negates all elements of 3x3 matrix A
Definition: matrix.c:147
void fveqRu(float fv[], float fR[][3], float fu[], int8 itranspose)
function rotates 3x1 vector u onto 3x1 vector using 3x3 rotation matrix fR. the rotation is applied i...
Definition: matrix.c:820
void fmatrixAeqInvA(float *A[], int8 iColInd[], int8 iRowInd[], int8 iPivot[], int8 isize, int8 *pierror)
function uses Gauss-Jordan elimination to compute the inverse of matrix A in situ on exit...
Definition: matrix.c:666
void f3x3matrixAeqAxScalar(float A[][3], float Scalar)
function multiplies all elements of 3x3 matrix A by the specified scalar
Definition: matrix.c:128
void fmatrixAeqI(float *A[], int16 rc)
function sets the matrix A to the identity matrix
Definition: matrix.c:87
void fComputeEigSlice(float fmatA[10][10], float fmatB[10][10], float fvecA[10], int8 i, int8 j, int8 iMatrixSize)
Definition: matrix.c:572
void fEigenCompute10(float A[][10], float eigval[], float eigvec[][10], int8 n)
function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1] stored in the top left of a 10x10 array A[10][10]
Definition: matrix.c:234
int16_t int16
Definition: sensor_fusion.h:56
int8_t int8
Definition: sensor_fusion.h:55